package com.cetccloud.ap.config.route.pedicate;

import cn.hutool.core.util.ReUtil;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.function.server.ServerRequest;

/**
 * @ClassName RegexPredicate
 * @Description 通过正则表达式匹配url
 * @Author superz
 * @Date 2021/4/9 22:48
 * @Version 1.0
 **/
public class RegexPredicate implements RequestPredicate {

    private String regex;

    public RegexPredicate(String regex) {
        this.regex = regex;
    }

    @Override
    public boolean test(ServerRequest request) {
        String path = request.requestPath().pathWithinApplication().value();
        return ReUtil.isMatch(regex, path);
    }
}
